<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<link rel="stylesheet" type="text/css" href="<%=basePath%>img/from.css">
<style type="text/css">
table tr{ height:25px;}
</style>
<script type="text/javascript">
jQuery(function(){
	$('#emoneyid').numberspinner({onChange:function(){
		doCount();
	}});
	$('#trade').numberspinner({onChange:function(){
		setGive();
	}});
	$('#moneyid').numberspinner({onChange:function(){
		doCount();
	}});
});
	function credit(){
		var r = $('#aaaForm').form('validate');
		if(!r) {
			return false;
		}
		//if(!writeMoneyCard(($('#moneyid').val()-0)+($('#moneybalanceNow').val()-0))) return;
		var writeMoney =$('#creditflag').val()==2 ? ($('#moneybalanceNow').val()-0) : ($('#moneyid').val()-0)+($('#moneybalanceNow').val()-0);
		if(!writeMoneyCard(writeMoney)) return;
		$.post("aba/addOrUpdate",$("#abaForm").serializeArray(),function(data){
			if(data.cflag == 2){
				$('#creditflag').val(2);
				$('#version').val(data.ver);
				$('#emoneyid').numberspinner('disable');
				$('#moneyid').numberspinner('disable');
				$('#btn-credit').linkbutton({text:'冲账'});
			}else{
				clean();
				$('#abaid').val("");
				$('#emoneyid').numberspinner('setValue','0');
				$('#moneyid').numberspinner('setValue','0');
				$('#btn-credit').linkbutton({text:'充值'});
			}
			$.messager.alert('提示',data.mes,'info');
		});
	}
	function showCardInfo(){
		clean();
		if(!readCardInfo()) return;
		$.post('aba/showCardInfo?abaid='+$('#abaid').val(),function(data){
			$.messager.show({
			       title: '提示',
			       msg: data.message,
			       timeout: 3000,
			       showType: 'slide'
			 });
			if(data.losted!=1){
				clean();
				return;
			}
			if(data.eflag){
				$('#eflag').text("开启");
				$('#emoneyid').numberspinner('enable');
			}else{
				$('#emoneyid').numberspinner('disable');
				$('#emoneyid').numberspinner('setValue','0');
				$('#eflag').text("未开启");
			}
			$('#moneycardlimit').text(data.moneycardlimit);
			$('#ownercard').text(data.aaa.ownercard);
			$('#username').text(data.aaa.username);
			$('#emoneybalance').val(data.emoney);
			$('#moneybalance').val(data.money);
			$('#version').val(data.version);
    	});
	}
	function clean(){
		$('#btn-credit').linkbutton({text:'充值'});
		$('#emoneyid').numberspinner('enable');
		$('#moneyid').numberspinner('enable');
		$('#username').text("");
		$('#ownercard').text("");
		$('#eflag').text("");
		$('#moneycardlimit').text("");
		$('#moneybalance').val("");
		$('#emoneybalance').val("");
		$('#moneybalanceNow').val("");
		$('#creditflag').val("1");
		$('#emoneyid').numberspinner('setValue','0');
		$('#moneyid').numberspinner('setValue','0');
	}
	function doCount(){
		var emoney = $('#emoneyid').val()-0;
		var money = $('#moneyid').val()-0;
		var mustMoney = emoney+money;
		$('#mustMoney').text(mustMoney);
		$('#give').text(0);
		$('#trade').numberspinner('setValue',mustMoney);
	}
	function setGive(){
		var emoney = $('#emoneyid').val()-0;
		var money = $('#moneyid').val()-0;
		var trade = $('#trade').val()-0;
		var mustMoney = emoney+money;
		$('#give').text(trade-mustMoney);
	}
	function readCardInfo(){
		var cardid = findNormalCard();
		if(cardid){
			$('#abaid').val(cardid);
			$('#moneybalanceNow').val(findMoneyCard());
			return true;
		}return false;
	}
</script>
<div style="background:#fafafa;padding:10px;">
	<div style="padding:3px 2px;margin-bottom:10px;border-bottom:1px solid #ccc"><div>充值菜单</div></div>
	<form id="abaForm" method="post" novalidate>
	<table>
		<tr><td><input name="creditflag" type="hidden" value="1" id="creditflag"><input name="version" type="hidden" id="version"><input type="hidden" id="creatuserid" value="<sec:authentication property="name"/>" name="creatuserid"></td></tr>
		<tr><td>用户卡号：</td><td><input name="abaid" id="abaid" onchange="showCardInfo();" style="width: 200" validType="length[3,12]" class="easyui-validatebox" required="true"> </td></tr>
		<tr><td>用户姓名：</td><td id="username"></td></tr>
		<tr><td>证件ID：</td><td id="ownercard"></td></tr>
		<tr><td>开启电子账户：</td><td id="eflag"></td></tr>
		<tr><td>电子钱包最大消费金额：</td><td id="moneycardlimit">0</td></tr>
		<tr><td>电子账户余额：   </td><td ><input  class="easyui-validatebox" required="true" name="emoneybalance" readonly="readonly" id="emoneybalance"></td></tr>
		<tr><td>电子钱包余额：</td><td ><input  class="easyui-validatebox" required="true" name="moneybalanceNow" readonly="readonly" id="moneybalanceNow"></td><td>电子钱包数据库余额(非同步)：</td><td ><input  class="easyui-validatebox" required="true" name="moneybalance" readonly="readonly" id="moneybalance"></td></tr>
		<tr>
			<td>电子账户充值金额：   </td><td><input onkeyup="doCount();" onchange="doCount();"  style="text-align:right;font-size: 23px;width: 150px;height: 28px;" maxlength="5" name="emoney" id="emoneyid" class="easyui-numberspinner" data-options="increment:10"  value="0" class="easyui-validatebox" required="true" ></td>
			<td>电子钱包充值金额：</td><td><input onkeyup="doCount();" onchange="doCount();" name="money" id="moneyid" style="text-align:right;font-size: 23px;width: 150px;height: 28px;" maxlength="5" class="easyui-numberspinner" data-options="increment:10"  value="0" class="easyui-validatebox" required="true" ></td>
		</tr>
		<tr>
			<td>实收金额：</td><td><input id="trade"  class="easyui-numberspinner" data-options="increment:10" onkeyup="setGive();" style="text-align:right;font-size: 23px;width: 150px;" maxlength="5"  value="0" ></td>
			<td>应收金额：</td><td  style="color: red;font-weight:bold;font-size: 23px;" align="center" id="mustMoney">0</td>
		</tr>
		<tr>
			<td>找零：</td><td id="give" style="color: green;font-weight:bold;font-size: 23px;" align="center" >0</td>
		</tr>
		<tr>
		
		</tr>
	</table>
	</form>
	<a href="#" id="btn-back" onclick="showCardInfo();" class="easyui-linkbutton" iconCls="icon-back">读卡</a>
	<a href="#" id="btn-credit" onclick="credit();" class="easyui-linkbutton" iconCls="icon-save">充值</a>
</div>